package org.opencv.test1;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

public class Upload extends Thread{

	public Bitmap currentImage;
	Socket socket;
	OutputStream os;

	public Upload(Bitmap currentImage) {
		this.currentImage = currentImage;

		try {

			socket = new Socket("192.168.0.186",12345);
			os = socket.getOutputStream();
			this.start();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    
	}
	
	@Override
	public synchronized void start() {
		// TODO Auto-generated method stub
		super.start();
	}
	
	@Override
	public void run() {
		while(true){
			// TODO Auto-generated method stub
			try {
				//this.currentImage.compress(format, MIN_PRIORITY, stream)
				this.currentImage.compress(CompressFormat.PNG,MIN_PRIORITY , os);
				os.flush();
				try{
					this.sleep(10000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}  

			} catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}


}
